import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Test01 {

    public static String regex = "[0-9]";

    public static void main(String[] args) {
        String s = "-234 fgt";
        int i = strToInt(s);
        System.out.println(i);
    }

    public static int strToInt(String str) {

        int res = 0;
        if(str==null){
            return res;
        }
        str = str.replaceAll(" ","");
        if(str == ""){
            return res;
        }

        String regex = "0-9\\-";

        if(!regex.matches(String.valueOf(str.charAt(0)))){
            return res;
        }

        StringBuilder sb = new StringBuilder();
        for(int i=0; i<str.length(); i++){
            if(!regex.matches(String.valueOf(str.charAt(i)))){
                break;
            }else{
                sb.append(str.charAt(i));
            }
        }

        res = Integer.parseInt(sb+"") ;
        res = res<Integer.MIN_VALUE ? Integer.MIN_VALUE : res;
        res = res>Integer.MAX_VALUE ? Integer.MAX_VALUE:res;

        return res;
    }


}
